local Json = require("common.Json")
local Msg = require("core.Msg")

InnerDataWRegList = InnerDataWRegList or {}

function Register(oType, oHandleW)
    InnerDataWRegList[oType] = {handleW = oHandleW}
end

function ProcessWCB(oHuman, oType, oData)
    local nData = Json.Decode(oData) 
    if InnerDataWRegList[oType] and InnerDataWRegList[oType].handleW then
        InnerDataWRegList[oType].handleW(oHuman, oType, nData)
    end
end

function Send2LInnerData(oHuman, oType, oData, logicID)
    local nMsg = Msg.wl.WL_INNER_DATA
    nMsg.type = oType
    
    nData = Json.Encode(oData)
    if nData then
        nMsg.data = nData
    else
        return false
    end
    
    if oHuman then
        Msg.send2logic(nMsg, oHuman._id)
    else
        if not logicID then
            for i = 0, 3 do
                Msg.send2logic_id(nMsg, i)
            end
        else
            Msg.send2logic_id(nMsg, logicID)
        end
    end
    return true
end
